#!/env/bin/python
#Author:tanqing
# -*- coding: utf-8 -*-
# @Time        : 2021/1/4 14:44
import shutil
from pathlib import Path
import random

# 创建目录
p = Path('test')
if p.exists():
    shutil.rmtree(p)
p1 = p / "b"
p2 = p1 / "c"
p3 = p2 / "d"
p3.mkdir(parents=True)

# 创建随机文件
rand_text=[chr(i+ord("a")) for i in range(26)]
for i in (p,p1,p2,p3):
    for x in range(50):
        filename=''.join(random.sample(rand_text,4))
        file_path=i/filename
        file_path.touch()


dst=Path('dst')
if dst.exists():
    shutil.rmtree(dst)

# 定义筛选函数，返回集合
def ignore(src,names):
    def ignore_acl(name):
        if not(Path(src,name).is_dir() or name.startswith('x') or name.startswith('y') or name.startswith('z')):
            return name
    ignores=set(filter(ignore_acl,names))
    return ignores


shutil.copytree(p,dst,ignore=ignore)

# 做的不错